<?php
// application/lib/ResourceAbstract.php
/**
 * Lib_ResourceAbstract - base class for all resources
 *
 * Every resource should extend this class
 * and because of that impelment _getResource() method
 *
 * demo-zf application
 *
 * @author Adam Pilacki <adam.pilacki@gmail.com>
 */
abstract class Lib_ResourceAbstract
    extends Zend_Application_Resource_ResourceAbstract
{
    protected $_resource;

    /**
     * Common init method
     * Returns resource as singleton
     *
     * @return Zend_Application_Resource_ResourceAbstract
     */
    public function init()
    {
        if (null === $this->_resource) {
            $this->_resource = $this->_getResource();
        }
        return $this->_resource;
    }

    /**
     * Put resource initiate code here and return resource object or boolean or null value
     * returns mixed (e. g. resource object Zend_View, Zend_Layout, Zend_Session_Namespace)
     */
    abstract protected function _getResource();
}